package com.foxzzz.binary.search;

public class Solution392 {
    public boolean isSubsequence1(String s, String t) {
        if(s.equals(""))
            return true;
        int start=0;
        int match=0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = start; j < t.length(); j++) {
                if(s.charAt(i)==t.charAt(j)) {
                    start = j+1;
                    match++;
                    break;
                }
            }
            if(match==s.length())
            return true;
        }

        return false;
    }

    public boolean isSubsequence2(String s, String t) {
        if(s.equals("")||s.equals(t))
            return true;
        for (int j = 0,i=0; j < t.length(); j++) {
            if(s.charAt(i)==t.charAt(j)) {
                if(++i==s.length())
                    return true;
            }
        }

        return false;
    }


    public boolean isSubsequence(String s, String t) {
        int index = 0;
        for(char ch:s.toCharArray()){
            index = t.indexOf(ch,index);
            if(index == -1)
                return false;
            index++;
        }
        return true;
    }

    public static void main(String[] args) {
        new Solution392().isSubsequence("abc","ahbgdc");
    }
}
